﻿#include "baseinfo.h"

BaseInfo::BaseInfo(const QString &msgId,const qint64 &createTime,QWidget *parent)
    : QWidget{parent},
    msgId(msgId),
    createTime(createTime)
{

}
void BaseInfo::removeTextEdit(){
    if(textEdit!=nullptr){
        delete textEdit;
        textEdit=nullptr;
    }
}

QSize BaseInfo::scaleImage(const QString &imagePath){
    QPixmap pixmap(imagePath);
    if (pixmap.isNull()) {
        return QSize(0,0);
    }
    //按比例缩放图片
    //Qt::KeepAspectRatio保持长宽比
    //Qt::FastTransformation快速转换，提高处理速度，不考虑质量
    pixmap = pixmap.scaled(217, 217, Qt::KeepAspectRatio, Qt::FastTransformation);
    //设置最小的显示图片宽度为68
    if(pixmap.width()<68){
        pixmap=pixmap.scaledToWidth(68,Qt::FastTransformation);
    }
    //设置最小的显示图片高度为68
    if(pixmap.height()<68){
        pixmap=pixmap.scaledToHeight(68, Qt::FastTransformation);
    }
    return pixmap.size();
}

const QString& BaseInfo::getMsgId(){
    return this->msgId;
}
const qint64& BaseInfo::getCreateTime(){
    return this->createTime;
}
